package com.wondertek.poms.dao.po;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.wondertek.poms.common.constant.CurrentUser;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@Entity
@Table(name = "SELLING_PRICE")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SellingPrice implements Serializable {

	private static final long serialVersionUID = 6852432309562204276L;

	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SELLING_PRICE_SEQ")
	@SequenceGenerator(name = "SELLING_PRICE_SEQ", allocationSize = 1, sequenceName = "SELLING_PRICE_SEQ")
	private Long id;
	
	@Column(name = "SELLING_PRICE_NUM")
	private Long sellingPriceNum;
	
	@Column(name = "PRODUCT_ID")
	private Long productId;
	
	@Column(name = "PRICE")
	private String price;
	
	@Column(name = "DESCRIPTION")
	private String description;
	
	@Column(name = "NAME")
	private String name;
	
	@Column(name = "CREATOR")
	private String creator;
	
	@Column(name = "CREATE_TIME")
	private String createTime;

	public static void putTimeAndUser(SellingPrice sellingPrice) {
		sellingPrice.setCreator(CurrentUser.currUserName());
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(currentTime);
		sellingPrice.setCreateTime(dateString);
	}
}
